<!DOCTYPE html>
<html>
<!--frame传值后再添加新数据的实现方法尝试页面备份-->
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/admin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <link rel="stylesheet" href="../../static/css/app.css">
    <link rel="stylesheet" href="../../static/css/survey.css">
    <link rel="stylesheet" href="../../static/css/index.css">
    <![endif]-->


    <style type="text/css">
        span {
            cursor: pointer;
        }

        table {
            table-layout: fixed; /* 只有定义了表格的布局算法为fixed，下面td的定义才能起作用。 */
        }

        th {
            width: 100%;
            word-break: keep-all; /* 不换行 */
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用*/
            text-align: center;
        }
    </style>

</head>

<body style="background-color: #f0f0f0">

<div class="weadmin-body">
    <div class="block-survey">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">活动状态</label>
                    <div class="layui-input-inline">
                        <select id="selectBox" class="layui-input">
                            <option value="">请选择</option>
                            <option value="1">已通过</option>
                            <option value="2">未通过</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-btn layui-btn-normal" onclick="qureyData()">搜索</div>
                </div>
            </div>

        </form>
    </div>

    <table class="layui-table table" id="tableList">
        <colgroup>
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="40%">
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="20%">
            <col name="el-table_1_column_21" width="20%">

        </colgroup>
        <thead>
        <tr>
            <th style="text-align: center">序号</th>
            <th style="text-align: center">活动名称</th>
            <th style="text-align: center">活动封面</th>
            <th style="text-align: center">活动开始时间</th>
            <th style="text-align: center">活动结束时间</th>
            <th style="text-align: center">活动地址</th>
            <th style="text-align: center">状态</th>

            <th style="text-align: center">审核</th>

        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <div style="text-align: center" id="foot"></div>
</div>

<script type="text/javascript" src="../../static/js/jquery.min.js"></script>

<script src="../../static/js/republic.js" charset="utf-8"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#date', //指定元素
            theme: '#BDBDBD',
        });
    });
    var jsessionid = localStorage.getItem("jsessionid")
    var imageRPUrl = 'https://cjrm-prod.oss-cn-shenzhen.aliyuncs.com/'


    function qureyData() {
        var status =$("#selectBox").val()
        $.ajax({
            type: "get",
            url: serverUrl + '/activity/getALlActivity/1/' + status + ';jsessionid=' + jsessionid,

            success: function (r) {
                if (r.code == 0) {
                    $("#tableList tbody").html("");
                    $.each(r.data.results, function (key, value) {
                        $("#tableList tbody").append("<tr>" +
                            "<th style='text-align: center'>" + Number(key + 1) + "</th>" +
                            "<th style='text-align: center'>" + value.title + "</th>" +
                            "<th style='text-align: center'><img src=" + imageRPUrl + value.cover + "  /></th>" +
                            "<th style='text-align: center'>" +setTime(value.signUpBeginTime) + "</th>" +
                            "<th style='text-align: center'>" + setTime(value.signUpEndTime) + "</th>" +
                            "<th style='text-align: center'>" + value.location + "</th>" +
                            "<th style='text-align: center'>" +setState(value.status) + "</th>" +
                            "<th style='text-align: center'>" +
                            "<span style='display: "+setTF(value.status)+"' onclick='editCourse("+value.id+")'>通过</span>" +
                            "<span style='display: "+setTF(value.status)+"' onclick='deleteRecommCourse("+value.id+")'>  不通过</span>" + "</th>" +
                            "</tr>");
                    });
                    layui.use('laypage', function () {
                        var laypage = layui.laypage;
                        laypage.render({
                            elem: 'foot',
                            count: r.data.totalRecord,
                            limit: r.data.pageSize,
                            jump: function (obj, first) {
                                //obj包含了当前分页的所有参数，比如：
                                //首次不执行
                                if (!first) {
                                    var status =$("#selectBox").val()
                                    $.ajax({
                                        type: "get",
                                        url: serverUrl + '/activity/getALlActivity/' + obj.curr + '/' + status + ';jsessionid=' + jsessionid,
                                        success: function (r) {
                                            if (r.code == 0) {
                                                $("#tableList tbody").html("");
                                                $.each(r.data.results, function (key, value) {
                                                    $("#tableList tbody").append("<tr>" +
                                                        "<th style='text-align: center'>" + Number(key + 1) + "</th>" +
                                                        "<th style='text-align: center'>" + value.title + "</th>" +
                                                        "<th style='text-align: center'><img src=" + imageRPUrl + value.cover + "  /></th>" +
                                                        "<th style='text-align: center'>" +setTime(value.signUpBeginTime) + "</th>" +
                                                        "<th style='text-align: center'>" + setTime(value.signUpEndTime) + "</th>" +
                                                        "<th style='text-align: center'>" + value.location + "</th>" +
                                                        "<th style='text-align: center'>" +setState(value.status) + "</th>" +
                                                        "<th style='text-align: center'>" +
                                                        "<span style='display: "+setTF(value.status)+"' onclick='editCourse("+value.id+")'>通过</span>" +
                                                        "<span  style='display: "+setTF(value.status)+"' onclick='deleteRecommCourse("+value.id+")'>  不通过</span>" + "</th>" +
                                                        "</tr>");
                                                });
                                            }

                                        }
                                    })
                                }
                            }
                        });
                    });
                } else if (r.code = 2) {
                    document.location.href = "./login.html";
                } else {
                    // alert("失败")
                }
            },
        });


    }

    qureyData()



    function setTime(data) {
        var date = new Date(data*1000)
        var y = date.getFullYear()
        var m = date.getMonth() +1
        var d = date.getDate()
        var h = date.getHours()>10?date.getHours():'0'+date.getHours()
        var se = date.getMinutes()>10?date.getMinutes():'0'+date.getMinutes()
        return [y,m,d].join('/')+' '+[h,se].join(":")
    }
    function editCourse(data) {
        $.ajax({
            type: "get",
            url: serverUrl + '/activity/auditActivity/' + data + '/1' + ';jsessionid=' + jsessionid,
            success:function () {
                layer.msg("已通过")
                qureyData()
            }
        })

    } 
    function deleteRecommCourse(data) {
        $.ajax({
            type: "get",
            url: serverUrl + '/activity/auditActivity/' + data + '/2' + ';jsessionid=' + jsessionid,
            success:function () {
                layer.msg("已拒绝")
                qureyData()
            }
        })

    }
    function setTF(data) {
        console.log(Number(data-1))
       return Number(data-1)>-1?'none':'inline'
    }

    function setState(data) {
       switch (data) {
           case 0:
               return '未审核'
               break;
           case 1:
               return '通过'
               break;
           case 2:
               return '不通过'
               break;
       }
    }


</script>
</body>

</html>